package com.zhaorenxueapp;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;

import com.zhaorenxueapp.LIstView.Bean;
import com.zhaorenxueapp.LIstView.MyAdapterWithCommViewHolder;
import com.zhaorenxueapp.Text.TitleBuilder;
import com.zhaorenxueapp.Xutils.MyAdapter;

import org.xutils.ImageManager;
import org.xutils.common.util.DensityUtil;
import org.xutils.image.ImageOptions;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class SettingFragment extends Fragment {
    private View view;
    private View.OnClickListener leftCilckListener;
    private View.OnClickListener rightCilckListener;
    private ListView mListView;
    private List<Bean> mDatas;
    private MyAdapterWithCommViewHolder mAdapterWithCommViewHolder;
    @ViewInject(R.id.tv_title)
    private ImageView imageView;
    public SettingFragment() {
    }
    ImageOptions imageOptions;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.tab04, container, false);
        imageOptions = new ImageOptions.Builder()
                .setSize(DensityUtil.dip2px(120), DensityUtil.dip2px(120))
                .setRadius(DensityUtil.dip2px(5))
                // 如果ImageView的大小不是定义为wrap_content, 不要crop.
                .setCrop(true)
                // 加载中或错误图片的ScaleType
                //.setPlaceholderScaleType(ImageView.ScaleType.MATRIX)
                .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
                //设置加载过程中的图片
                .setLoadingDrawableId(R.drawable.ic_launcher)
                //设置加载失败后的图片
                .setFailureDrawableId(R.drawable.ic_launcher)
                //设置使用缓存
                .setUseMemCache(true)
                //设置支持gif
                .setIgnoreGif(false)
                //设置显示圆形图片
//      .setCircular(false)
                .build();
        initTitle();
        initDatas();
        initView();
        return view;
    }

    private void initTitle() {
        /**
         * 1.设置左边的图片按钮显示，以及事件
         * 2.设置中间TextView显示的文字
         * 3.设置右边的图片按钮显示，并设置事件
         */
        new TitleBuilder(view)
//                .setLeftImageRes(R.drawable.layout_top_back)
                .setLeftTextOrImageListener(leftCilckListener)
                .setMiddleTitleText("设置")
//                .setRightImageRes(R.drawable.layout_right_menu)
                .setRightTextOrImageListener(rightCilckListener);

    }
    private void initDatas() {
        mDatas = new ArrayList<Bean>();
//        Bean bean = new Bean("Android新技能 Get 1", "Android-打造万能的ListView和GridView适配器", "2015-08-05", "10086");
        Bean bean=new Bean();
        bean.setImgUrl(R.drawable.ic_launcher);
        mDatas.add(bean);
//        mAdapter=new MyAdapter(this,mDatas);
        mAdapterWithCommViewHolder = new MyAdapterWithCommViewHolder(getActivity(), mDatas, R.layout.iten);
//        mAdapterWithCommAdapter = new MyAdapterWithCommAdapter(this, mDatas, R.layout.item);
    }

    /**
     * 为列表设置适配器
     *
     * @return void
     * @author Yann
     * @date 2015-8-5 下午10:15:04
     */
    private void initView() {
        mListView = (ListView) view.findViewById(R.id.View);
        mListView.setAdapter(mAdapterWithCommViewHolder);
//        mListView.setAdapter(mAdapterWithCommAdapter);
    }
    public void onCreate() {

    }
}
